package com.example.mobile203zlw20216061300616;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    private RecyclerView recycle;
    private Button button;
    private List<Student> list=new ArrayList<>();
    SQLiteDatabase database;
    mySQList mySQList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        main_Adapter main_adapter=new main_Adapter(list);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        recycle.setLayoutManager(linearLayoutManager);
        recycle.setAdapter(main_adapter);
        mySQList=new mySQList(this,"staff.db",null,1);
        database=mySQList.getReadableDatabase();
        Cursor cursor = database.query("student", null, null, null,
                null, null, null);
        if (cursor.moveToFirst()) {
            do {
                String name = cursor.getString(cursor.getColumnIndex("name"));
                String skill = cursor.getString(cursor.getColumnIndex("skill"));
                int maney = cursor.getInt(3);
                list.add(new Student(name, skill, maney));
            } while (cursor.moveToNext());
        }
        cursor.close();
        database.close();
    }
    public void tianjia(View view) {
            Intent intent = new Intent(MainActivity.this, MainActivity2.class);
            startActivity(intent);
        }
    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        recycle = (RecyclerView) findViewById(R.id.recycle);
        button = (Button) findViewById(R.id.button);
    }
}